# -*- coding: utf-8 -*-
# @Time    : 2021/10/22 7:04
# @Author  : super

from book import BookClass

class BookManagementSystem(object):
	admin_list = [
		{"username": "admin", "password": "123456"}
	]
	books_list = []

	def main(self):
		self.mune()

	def mune(self):
		'''菜单栏'''
		print("0.管理员登录")
		print("1.会员登录")
		try:
			numbers = int(input("请选择操作："))
			if numbers == 0:
				self.admin_login()
			elif numbers == 1:
				pass
			else:
				print("输入错误，请重新输入！")
				self.main()
		except Exception as e:
			raise e


	def admin_login(self):
		'''登录管理员账号'''
		username = input("请输入账号名称：")
		password = input("请输入密码：")
		for i in self.admin_list:
			if i["username"] == username and i["password"] == password:
				print("欢迎登录，管理员！")
				self.book_operation()
			else:
				print("账号密码不存在，请重新输入！")
				self.admin_login()

	def book_operation(self):
		'''图书操作'''
		print("请选择对应操作：")
		print("1.收录图书")
		print("2.删除图书")
		print("3.图书排序")
		print("4.借阅情况查询")
		print("0.退出登录")
		try:
			numbers = int(input("请选择对应的编号："))
			if numbers == 1:
				self.save_books()
			elif numbers == 2:
				self.delete_books()
			elif numbers == 3:
				self.sort_books()
			elif numbers == 4:
				self.member_books()
			elif numbers == 0:
				exit(0)

		except Exception as e:
			raise e
			# self.book_operation()

	def save_books(self):
		try:
			f = open("books.txt", "r", encoding = "utf-8")
			print(type(f.read()))

			
			list = eval(f.read())
			self.books_list = [BookClass(i["book_name"], i["user_name"], i["book_id"], i["book_price"], i["book_press"], i["press_data"], i["collection_data"], i["class_number"], i["book_status"]) for i in list]
			new_list = [i.__dict__ for i in self.students]
			print(new_list)
		except Exception as e:
			raise e
		finally:
			f.close()

	def delete_books(self):
		pass

	def sort_books(self):
		pass

	def member_books(self):
		pass

if __name__ == '__main__':
    bms = BookManagementSystem()
    bms.main()